/*
 *  Copyright (C) 2010 Matthias Buch-Kromann <mbk.isv@cbs.dk>
 * 
 *  This file is part of the MatrixParser package.
 *  
 *  The MatrixParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.osdtsystem.matrixparser.featureextraction;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.osdtsystem.matrixparser.parsers.ParsingModel;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class FeatureExtractorRegistry {
    final ParsingModel model;
    final Map<String,FirstOrderExtractorUnlabelled> firstOrderUnlabelled
            = new HashMap<String,FirstOrderExtractorUnlabelled>();
    final Map<String,FirstOrderExtractorLabelled> firstOrderLabelled
            = new HashMap<String,FirstOrderExtractorLabelled>();
    final Map<String,FeatureExtractor> higherOrder
            = new HashMap<String,FeatureExtractor>();

    public FeatureExtractorRegistry(ParsingModel model, String extractors) {
        // Add unlabelled MST extractors
        this.model = model;
        for (String name : extractors.split(":")) {
            if (name.equals("mst1U")) {
                addExtractor(name, new FirstOrderExtractorUnlabelledNew(model));
            } else if (name.equals("mst1L")) {
                addExtractor(name, new FirstOrderExtractorLabelledNew(model));
            } else if (name.equals("cframes")) {
                addExtractor(name, new HigherOrderMbkCframes(model));
            } else if (name.equals("localorder")) {
                addExtractor(name, new HigherOrderMbkLocalOrder(model));
            } else if (name.equals("roles")) {
                addExtractor(name, new HigherOrderMbkRoles(model));
            }
        }
    }

    final void addExtractor(String name, FeatureExtractor extractor) {
        if (extractor instanceof FirstOrderExtractor) {
            if (extractor instanceof FirstOrderExtractorUnlabelled) {
                firstOrderUnlabelled.put(name, (FirstOrderExtractorUnlabelled) extractor);
            }
            if (extractor instanceof FirstOrderExtractorLabelled) {
                firstOrderLabelled.put(name, (FirstOrderExtractorLabelled) extractor);
            }
        } else {
            higherOrder.put(name, extractor);
        }
    }

    public Collection<FirstOrderExtractorUnlabelled> firstOrderUnlabelled() {
        return firstOrderUnlabelled.values();
    }

    public Collection<FirstOrderExtractorLabelled> firstOrderLabelled() {
        return firstOrderLabelled.values();
    }

    public Collection<FeatureExtractor> higherOrder() {
        return higherOrder.values();
    }

    public UnionExtractor unionExtractor() {
        return new UnionExtractor(model, this);
    }
}
